/*
 * MahasiswaDaoImpl.java
 *
 * Created on June 20, 2007, 11:43 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package latihanibatis.dao;

import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.template.SqlMapDaoTemplate;
import java.util.List;
import java.util.Map;
import latihanibatis.domain.Mahasiswa;

/**
 *
 * @author javamaniac
 */
public class MahasiswaDaoImpl extends SqlMapDaoTemplate implements MahasiswaDao {
    
    /**
     * Creates a new instance of DaerahPasarDaoImpl
     *
     * @param daoManager
     */
    public MahasiswaDaoImpl(DaoManager daoManager) {
        super(daoManager);
    }
    
    public void insertMhs(Mahasiswa mhsBaru) {
        try {
            daoManager.startTransaction();
            
            insert("insertMhs", mhsBaru);
            
            daoManager.commitTransaction();
        } finally {
            daoManager.endTransaction();
        }
    }
    
    public void updateMhs(final Map arrUpdate) {
        try {
            daoManager.startTransaction();
            
            update("updateMhs", arrUpdate);
            
            daoManager.commitTransaction();
        } finally {
            daoManager.endTransaction();
        }
    }
    
    public int deleteMhs(final int prmNIM) {
        Mahasiswa mhsDel = new Mahasiswa();
        mhsDel.setNim(prmNIM);
        
        final int row = delete("hapusMhs", mhsDel);
        
        return row;
    }
    
    @Override
    public List selectAllMhs() {
        final List list = queryForList("selectAllMhs", null);
        
        return list;
    }
    
    public Mahasiswa selectMhsByNim(final int prmNIM) {
        Mahasiswa mhs = new Mahasiswa();
        mhs.setNim(prmNIM);
        
        final Mahasiswa result = (Mahasiswa) queryForObject("getMhsByNim", mhs);
        
        return result;
    }

    public List searchMhs(final Map searchKeyword) {
        return queryForList("searchMhs", searchKeyword);
    }
}
